package org.sikyon.chocolatebiscuit.datamarket;

import org.sikyon.chocolatebiscuit.model.entities.Identifiable;

import java.util.Map;

public abstract class AbstractMarket implements Market {

    /**
     * @return A (possibly read-only) map of the Entity types & their Stores your system supports.
     */
    protected abstract Map<Class<? extends Identifiable<?>>, Store<? extends Identifiable<?>, ?>> stores();

    public <E extends Identifiable<K>, K> Store<E, K> getStoreFor(Class<E> clazz) {
        // TODO consider thread safe access to the stores hashmap
        Store<E, K> store;
        //noinspection unchecked
        store = (Store<E, K>) stores().get(clazz);
        return store;
    }
}
